#include<bits/stdc++.h>
using namespace std;
struct zd{
	string word;
	int page;
};
int main(){
	freopen("scanwords.in" , "r" , stdin);
	freopen("scanwords.out" , "w" , stdout);
	map<string , int>mp;
	int n , m;
	cin >> n;
	zd zd[10010];
	for(int i = 1 ; i <= n ; i++){
		cin >> zd[i].word >> zd[i].page;
		mp[zd[i].word] = zd[i].page;
	}
	cin >> m;
	for(int i = 1 ; i <= m ; i++){
		string s;
		cin >> s;
		cout << mp[s] << endl;
	}
	return 0;
}
